<?php
session_start();

if(!isset($_SESSION['userid']))//检查 userid 是否已经设置，如果没有设置，提示未登录并跳转首页
{
    echo "<script>alert('您尚未登录！')</script>";
    echo "<script>window.location.href='index.php'</script>";

}

include ('mysqli_connect.php');

$userid=$_SESSION['userid'];

$sql="select user_name from user_table where user_id={$userid}";
$res=mysqli_query($dbc,$sql);
$result=mysqli_fetch_array($res);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>影视管理系统&emsp;密码修改</title>
    <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style>
        body{
            width: 100%;
            overflow: hidden;
            background: url("300046-106.jpg") no-repeat;
            background-size:cover;
            color: antiquewhite;
        }
    </style>
</head>
<body>
<nav class="navbar navbar-default navbar-static-top" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="#">我的影视库</a>
        </div>
        <div>
            <ul class="nav navbar-nav">
                <li><a href="user_index.php">主页</a></li>
                <li><a href="user_querymovie.php">影视查询</a></li>-->
                <li><a href="user_sheet.php">我的收藏</a></li>-->
                <li class="active dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">个人信息<b class="caret"></b></a>

                    <ul class="dropdown-menu">
                        <li><a href="user_info.php">用户信息</a></li>
                        <li><a href="user_repass.php">修改密码</a></li>
                    </ul>
                </li>
                <li><a href="index.php">退出</a></li>
            </ul>
        </div>
    </div>
</nav>
<h1 style="text-align: center"><?php echo $result['user_name'];  ?>，您好</h1><br/>
<h2 style="text-align: center; color: darkblue"><b>您可以在下方修改密码：</b></h2><br/><br/>
<form action="user_repass.php" method="post"  style="text-align: center">
    <label><br/><input type="password" name="pass1" placeholder="请输入新的密码" class="form-control"></label><br/><br/>
    <label><br/><input type="password" name="pass2" placeholder="确认新的密码" class="form-control"></label><br/><br/>
    <input type="submit" value="提交" class="btn btn-default">
    <input type="reset" value="重置"  class="btn btn-default">
</form>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST")
{
    $passa = $_POST["pass1"];
    $passb = $_POST["pass2"];
    if($passa==$passb){
        $sql="update user_table set user_password='{$passa}' where user_id={$userid}";
        $res=mysqli_query($dbc,$sql);
        if($res==1)
        {
            echo "<script>alert('密码修改成功！请重新登陆！')</script>";
            echo "<script>window.location.href='index.php'</script>";
        }

    }
    else{
        echo "<script>alert('两次输入密码不同，请重新输入！')</script>";

    }

}


?>
</body>
</html>